﻿using Aribaccio;
using Aribaccio.Device;
using BDPAutodetect.Device;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BDPAutodetect.Simcore
{
    /// <summary>
    /// 
    /// </summary>
    public partial class DeviceCommandData : ObservableModel
    {
        /// <summary>
        /// 设备指标类型
        /// </summary>
        public string TargetType { get; set; }
        /// <summary>
        /// 设备指标模块
        /// </summary>
        public string TargetModule { get; set; }
        /// <summary>
        /// 设备指标指令[对应接收指令]
        /// </summary>
        public string TargetCommand { get; set; }
        /// <summary>
        /// 响应返回指令
        /// </summary>
        public string ResponseCommand { get; set; }
        /// <summary>
        /// 响应状态标识（是否返回数据）
        /// </summary>
        public bool ResponseStatus { get; set; }

        /// <summary>
        /// 实际接收指令内容
        /// </summary>
        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(RealCommandContentDisplay))]
        protected string realCommandContent = string.Empty;

        /// <summary>
        /// 实际接收指令显示内容
        /// </summary>
        public string RealCommandContentDisplay => this.RealCommandContent?.Replace("\r", "<cr>")?.Replace("\n", "<lf>") ?? string.Empty;

        /// <summary>
        /// 实际接收指令时间
        /// </summary>
        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(RealCommandReceivedTimeDisplay))]
        protected DateTime realCommandReceivedTime = DateTime.Now;

        /// <summary>
        /// 实际接收指令显示时间
        /// </summary>
        public string RealCommandReceivedTimeDisplay => this.RealCommandReceivedTime.ToString("yyyy-MM-dd HH:mm:ss.fff");

        /// <summary>
        /// 实际响应返回指令
        /// </summary>
        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(RealResponseCommandDisplay))]
        protected string realResponseCommand = string.Empty;
        /// <summary>
        /// 实际响应返回指令显示
        /// </summary>
        public string RealResponseCommandDisplay => this.RealResponseCommand?.Replace("\r", "<cr>")?.Replace("\n", "<lf>") ?? string.Empty;

        /// <summary>
        /// 设备指标类型
        /// </summary>
        public DeviceTargetType DeviceTargetType => TargetType.ToEnum<DeviceTargetType>();
        /// <summary>
        /// 设备指标类型
        /// </summary>
        public DeviceModule DeviceModule => this.TargetModule.ToEnum<DeviceModule>();

        /// <summary>
        /// 构造函数
        /// </summary>
        public DeviceCommandData()
        {
            this.TargetType = DeviceTargetType.None.ToStringName();
            this.TargetModule = DeviceModule.None.ToStringName();
            this.TargetCommand = string.Empty;
            this.ResponseCommand = string.Empty;
            this.ResponseStatus = false;
        }

        /// <summary>
        /// 深度克隆
        /// </summary>
        /// <returns></returns>
        public DeviceCommandData CloneDeep()
        {
            return new DeviceCommandData()
            {
                TargetType = this.TargetType,
                TargetModule = this.TargetModule,
                TargetCommand = this.TargetCommand,
                ResponseCommand = this.ResponseCommand,
                ResponseStatus = this.ResponseStatus
            };
        }
    }
}
